package com.egao.appo.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.appo.entity.PayRecord;
import com.egao.appo.service.PayRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 交费记录
 * @author : Doman
 * @date : 2021-07-23 09:43:58
 * @version ：1.0
 */

@Api(tags = "交费记录")
@RestController
@RequestMapping("/api/appo/payRecord")
public class PayRecordController extends BaseController {

	@Autowired
	private PayRecordService payRecordService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('appo:payRecord:list')")
    //@OperLog(value = "交费记录", desc = "分页查询")
    @ApiOperation(value ="分页查询交费记录",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "payUserId:用户id\n" +
        "type:类型: 缴费,提成\n" +
        "price:金额\n" +
        "operateUserId:操作人\n" +
        "remark:备注\n" +
        "orderNum:排序\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, PayRecord payRecord) throws Exception{
        return payRecordService.list(page, payRecord, getLoginUser());
    }

    /**
     * 查询全部交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:list')")
    //@OperLog(value = "交费记录", desc = "查询全部")
    @ApiOperation("查询全部交费记录")
    @GetMapping()
    public JsonResult list(PayRecord payRecord){
        return payRecordService.list(payRecord, getLoginUser());
    }

    /**
     * 根据id查询交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:list')")
    //@OperLog(value = "交费记录", desc = "根据id查询")
    @ApiOperation("根据id查询交费记录")
    @GetMapping("/get")
    public JsonResult get(PayRecord payRecord) {
        return payRecordService.getById(payRecord);
		// 使用关联查询
        //PageParam<payRecord> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<payRecord> records = payRecordService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:save')")
    @OperLog(value = "缴费", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加交费记录",notes = "" +
            "payUserId:用户id\n" +
            "type:类型: 缴费,提成\n" +
            "price:金额\n" +
            "operateUserId:操作人\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/pay")
    public JsonResult pay(PayRecord payRecord) {
        return payRecordService.pay(payRecord, getLoginUser());
    }

    /**
     * 添加交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:save')")
    @OperLog(value = "交费记录", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加交费记录",notes = "" +
            "payUserId:用户id\n" +
            "type:类型: 缴费,提成\n" +
            "price:金额\n" +
            "operateUserId:操作人\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping()
    public JsonResult save(PayRecord payRecord) {
        return payRecordService.save(payRecord, getLoginUser());
    }

    /**
     * 修改交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:update')")
    @OperLog(value = "交费记录", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改交费记录",notes = "" +
            "id:id\n" +
            "payUserId:用户id\n" +
            "type:类型: 缴费,提成\n" +
            "price:金额\n" +
            "operateUserId:操作人\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "PUT")
    @PutMapping()
    public JsonResult update(PayRecord payRecord) {
        return payRecordService.update(payRecord, getLoginUser());
    }

    /**
     * 删除交费记录
     */
    @PreAuthorize("hasAuthority('appo:payRecord:remove')")
    @OperLog(value = "交费记录", desc = "删除", result = true)
    @ApiOperation("删除交费记录")
    @DeleteMapping("/remove")
    public JsonResult remove(PayRecord payRecord ) {
        return payRecordService.remove(payRecord, getLoginUser());
    }

    /**
     * 批量添加交费记录
     */
    /**@RequiresPermissions("appo:payRecord:save")
    @OperLog(value = "交费记录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<PayRecord> list) {
        if (payRecordService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改交费记录
     */
    /**@RequiresPermissions("appo:payRecord:update")
    @OperLog(value = "交费记录", desc = "批量修改", result = true)
    @ResponseBody
    @PutMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<PayRecord> batchParam) {
        if (batchParam.update(payRecordService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除交费记录
     */
    /**@RequiresPermissions("appo:payRecord:remove")
    @OperLog(value = "交费记录", desc = "批量删除", result = true)
    @ResponseBody
    @DeleteMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (payRecordService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
